// vue-router@4它的写法稍有变化
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
const routes = [
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/Register.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/Home.vue'),
        children: [
            {
                path: '/home/yangyang',
                name: 'yangyang',
                component: () => import('@/views/home/YangYang.vue')
            },
            {
                path: 'zhilong/:id',//占位符
                name: 'zhilong',
                component: () => import('@/views/home/ZhiLong.vue'),
                beforeEnter: () => {
                    // ...
                    console.log('路由独享');
                }
            }
        ]
    },
    {
        path: '/',
        redirect: {
            path: '/home'
        }
    },
    // 通配符 notFound 
    /* {
        path: '*',
        component: () => import('@/views/NotFound.vue')
    } */
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/NotFound.vue')
    }
]

// createRouter创建路由器
const router = createRouter({
    // hash模式
    // history: createWebHashHistory(),
    // history模式
    history: createWebHistory(),
    routes
})


// 全局
router.beforeEach((to, from, next) => {
    console.log(to);
    console.log(from);
    next();
})
export default router;

// 时时刻刻看着是否自动弹出多余的东西，注意删除